package com.fish.gaiety.gateway.controller;

import com.fish.gaiety.gateway.base.GenericResponseBody;
import com.fish.gaiety.gateway.entity.UserApi;
import com.fish.gaiety.gateway.entity.dto.Authorities;
import com.fish.gaiety.gateway.entity.dto.User;
import com.fish.gaiety.gateway.service.AuthoritiesService;
import com.fish.gaiety.gateway.service.UserServiceDeprecated;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@RequestMapping("/user")
@RequiredArgsConstructor
@Slf4j
@Deprecated
public class UserControllerDeprecated {

    private final UserServiceDeprecated userServiceDeprecated;

    private final AuthoritiesService authoritiesService;

    @PostMapping()
    @GenericResponseBody
    public ResponseEntity<UserApi> addUser(@RequestBody UserApi user){
        return ResponseEntity
                .status(HttpStatus.CREATED)
                .body((userServiceDeprecated.addUser(user)));
    }

    @GetMapping()
    @GenericResponseBody
    public ResponseEntity<List<User>> getAllUser(){
        return ResponseEntity
                .status(HttpStatus.OK)
                .body(userServiceDeprecated.findAllUsers());
    }

    @GetMapping("/{id}")
    public ResponseEntity<User> getUser(@PathVariable("id") String id){
        return ResponseEntity.ok(userServiceDeprecated.getUser(id));
    }

    @GetMapping("/{id}/authorities")
    @GenericResponseBody
    public ResponseEntity<Authorities> getUserWithAuthorities(@PathVariable("id") String id){
        Authorities responseApi = authoritiesService.getBaseAuthorityByUserInfo(id);
        return ResponseEntity.ok(responseApi);
    }

    @GetMapping("/{id}/auth")
    @GenericResponseBody(successHttpStatus = HttpStatus.ACCEPTED)
    public ResponseEntity<Authorities> getUserWithAuthoritiesEnhance(@PathVariable("id") String id){
        return ResponseEntity
                .status(HttpStatus.ACCEPTED)
                .body(authoritiesService
                        .getBaseAuthorityByUserInfoEnhance(id));
    }
}
